/**
 * BrandBigData.com Inc.
 * Copyright (c) 2016 All Rights Reserved.
 */
package com.qibao.toolkit.facade.domain;

import org.apache.commons.lang3.builder.ToStringBuilder;

import java.io.Serializable;

/**
 * 用于评级系统结果返回对象
 *
 * @author wanggaowei
 * @version $Id:ResultModel.java, v0.1 2017-06-28 10:18 wanggaowei
 */
public class ResultModel<T> implements Serializable {
    private T data;
    private boolean success;
    private String message;

    private ResultModel(String message, T data, boolean success) {
        this.data = data;
        this.success = success;
        this.message = message;
    }

    private ResultModel() {
    }

    public static <T> ResultModel<T> SUCCESS(String message, T data) {
        return new ResultModel<>(message, data, true);
    }

    //    public static <T> ResultModel<T> SUCCESS(String message) {
    //        return new ResultModel<>(message, null, true);
    //    }

    public static <T> ResultModel<T> SUCCESS(T data) {
        return new ResultModel<>("success", data, true);
    }

    public static <T> ResultModel<T> FAIL(String message, T data) {
        return new ResultModel<>(message, data, false);
    }

    public static <T> ResultModel<T> FAIL(String message) {
        return new ResultModel<>(message, null, false);
    }

    public static <T> ResultModel<T> FAIL(T data) {
        return new ResultModel<>("fail", data, false);
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
